<?php
// 引入公共文件
include_once('./config/config.php');
// 引入数据库配置文件
include_once('./config/check.php');

$adminid = $_GET['jobid'] ?? 0;

$depsql = "select * from per_job";
$jobres = all($depsql);


// 数据回写
$sql = "select * from per_job where id=$adminid";

$admin = find($sql);
// var_dump($admin);
// exit;

if (!$admin) {
  ShowMsg('职位不存在','jobList.php');
  exit;
}

if ($_POST) {
  $name = isset($_POST['name'])? trim($_POST['name']):'';
  if (empty($name)) {
    ShowMsg('职位名不能为空');
    exit;
  }

  $sql = "select * from per_job where id=$adminid";
  $oldjob = find($sql);
  if (!$oldjob) {
    ShowMsg('职位不存在','jobList.php');
    exit;
  }

  $data = [];
  $data['name'] = $name;
  $result = edit('job',$data,"`id`=$adminid");
  if (!$result) {
    ShowMsg('编辑失败');
    exit;
  }
  


  ShowMsg('编辑成功','jobList.php');
  exit;
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
  <?php include_once('common/meta.php');?>
  </head>
  <body> 
    
    <?php include_once('common/header.php'); ?>

    <?php include_once('common/menu.php'); ?>

    <div class="content">
        <div class="header">
            <h1 class="page-title">添加职位</h1>
        </div>
        <ul class="breadcrumb">
            <li><a href="index.html">Home</a> <span class="divider">/</span></li>
            <li class="active">Index</li>
        </ul>

        <div class="container-fluid">
            <div class="row-fluid">
                    
                <div class="btn-toolbar">
                    <button class="btn btn-primary" onClick="location='jobList.php'"><i class="icon-list"></i> 职位列表</button>
                  <div class="btn-group">
                  </div>
                </div>

                <div class="well">
                    <div id="myTabContent" class="tab-content">
                      <div class="tab-pane active in" id="home">
                        <form method="post" enctype="multipart/form-data">
                            <label>职位ID</label>
                            <input type="text" class="input-xlarge" name="id" value="<?php echo $admin['id'];?>" readonly>
                            <span id="tips" style="display: none;"></span>
                            <label>职位名</label>
                            <select name="name" id="name">
                                <?php
                                  foreach ($jobres as $item) {
                                  echo "<option value='{$item['name']}'>{$item['name']}</option>";
                                }
                                ?>
                            </select>
                            
                            <label></label>
                            
                            <label></label>
                            <input class="btn btn-primary" type="submit" value="提交" />
                        </form>
                      </div>
                  </div>
                </div>

                <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                  </div>
                  <div class="modal-body">
                    
                    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
                  </div>
                  <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                  </div>
                </div>
                
                <?php include_once('common/footer.php'); ?>
                    
            </div>
        </div>
    </div>
  </body>
</html>
<?php include_once('common/script.php');?>

<script>
  $("#avatar").change(function(e){
    let file = e.target.files[0];
    let src = URL.createObjectURL(file);
   $("#preview").attr('src',src);
  })
</script>

